﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WhatSNew.AppCode
{
    /// <summary>
    /// 性别类型，可作为用户性别/性取向
    /// </summary>
    /// <remarks>Male 男性</remarks>
    /// <remarks>Female 女性</remarks>
    /// <remarks>OtherType 其他类型</remarks>
    /// <remarks>BothType 男女兼顾</remarks>
    public enum GenderType
    {
        Male = 0,
        Female = 1,
        OtherType = 2,
        BothType = 3,
        UnKnown = 4
    }

    /// <summary>
    /// 隐私控制类型
    /// </summary>
    /// <remarks>All 任何人可见</remarks>
    /// <remarks>Register 注册用户可见</remarks>
    /// <remarks>Follow 关注可见</remarks>
    /// <remarks>Self 仅自己可见</remarks>
    public enum PrivacyType
    {
        All = 0,
        Register = 1,
        Follow = 2,
        Self = 3
    }

    /// <summary>
    /// 用户个人数据
    /// </summary>
    public class UserPInfo
    {
        private int id;
        
        public int ID
        {
            get { return id; }
            set { id = value; }
        }

        private string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        private string email;

        public string Email
        {
            get { return email; }
            set { email = value; }
        }

        private string password;

        public string Password
        {
            get { return password; }
            set { password = value; }
        }

        private string birthday;

        public string Birthday
        {
            get { return birthday; }
            set { birthday = value; }
        }

        private string address;

        public string Address
        {
            get { return address; }
            set { address = value; }
        }

        private string image;

        public string Image
        {
            get { return image; }
            set { image = value; }
        }

        private GenderType gender;

        public GenderType Gender
        {
            get { return gender; }
            set { gender = value; }
        }

        private GenderType sexualOrie;

        public GenderType SexualOrie
        {
            get { return sexualOrie; }
            set { sexualOrie = value; }
        }

        private PrivacyType privOfEmail;

        public PrivacyType PrivOfEmail
        {
            get { return privOfEmail; }
            set { privOfEmail = value; }
        }

        private PrivacyType privOfGender;

        public PrivacyType PrivOfGender
        {
            get { return privOfGender; }
            set { privOfGender = value; }
        }

        private PrivacyType privOfAddress;

        public PrivacyType PrivOfAddress
        {
            get { return privOfAddress; }
            set { privOfAddress = value; }
        }

        private PrivacyType privOfSexualOrie;

        public PrivacyType PrivOfSexualOrie
        {
            get { return privOfSexualOrie; }
            set { privOfSexualOrie = value; }
        }

        private PrivacyType privOfBirthday;

        public PrivacyType PrivOfBirthday
        {
            get { return privOfBirthday; }
            set { privOfBirthday = value; }
        }

        private string introduction;

        public string Introduction
        {
            get { return introduction; }
            set { introduction = value; }
        }


        //构造函数
        public UserPInfo(String name, String password, int id = 0,
            String email = "", String birthday = "", 
            String address = "", GenderType gender = GenderType.UnKnown, 
            GenderType sexualOrie = GenderType.UnKnown,
            string introduction = "", string image = "",
            PrivacyType privOfAddress  = PrivacyType.Register,
            PrivacyType privOfBirthday  = PrivacyType.Register,
            PrivacyType privOfEmail  = PrivacyType.Register,
            PrivacyType privOfGender  = PrivacyType.Register,
            PrivacyType privOfSexualOrie  = PrivacyType.Register)

        {
            this.name = name;
            this.password = name;
            this.email = email;
            this.birthday = birthday;
            this.address = address;
            this.gender = gender;
            this.sexualOrie = sexualOrie;
            this.image = image;
            this.privOfBirthday = privOfAddress;
            this.privOfAddress = privOfAddress;
            this.privOfEmail = privOfEmail;
            this.privOfGender = privOfGender;
            this.privOfSexualOrie = privOfSexualOrie;
            this.introduction = introduction;
            this.id = id;
        }

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public UserPInfo()
        {
            id = -1;
            name = "";
            password = "";
            email = "";
            birthday = "";
            address = "";
            gender = GenderType.UnKnown;
            sexualOrie = GenderType.UnKnown;
            privOfBirthday = PrivacyType.Register;
            privOfAddress = PrivacyType.Register;
            privOfEmail = PrivacyType.Register;
            privOfGender = PrivacyType.Register;
            privOfSexualOrie = PrivacyType.Register;
            introduction = "";
            image = "";
        }
    }

    /// <summary>
    /// 用户类型
    /// </summary>
    /// <remarks>SuperAdministrator 超级管理员</remarks>
    /// <remarks>Administrator 普通管理员</remarks>
    /// <remarks>RegisterUser 普通注册用户</remarks>
    /// <remarks>NonRegister 非注册用户</remarks>
    public enum UserType
    {
        SuperAdministrator = 0,
        Administrator = 1,
        RegisterUser = 3,
        NonRegister = 4

    }

    /// <summary>
    /// 用户管理信息
    /// </summary>
    /// <remarks>privOfNews 0表示正常,正值表示封禁的天数</remarks>
    /// <remarks>privOfComment 0表示正常,正值表示封禁的天数</remarks>
    /// <remarks>privOfMessage 0表示正常,正值表示封禁的天数</remarks>
    /// <remarks>activation 0表示正常,正值表示封禁的天数</remarks>
    
    public class UserMInfo
    {
        private int id;

        public int ID
        {
            get { return id; }
            set { id = value; }
        }

        private UserType uType;

        public UserType UType
        {
            get { return uType; }
            set { uType = value; }
        }

        private int newsNum;

        public int NewsNum
        {
            get { return newsNum; }
            set { newsNum = value; }
        }

        private int commentNum;

        public int CommentNum
        {
            get { return commentNum; }
            set { commentNum = value; }
        }

        private int likeNum;

        public int LikeNum
        {
            get { return likeNum; }
            set { likeNum = value; }
        }

        private int dislikeNum;

        public int DislikeNum
        {
            get { return dislikeNum; }
            set { dislikeNum = value; }
        }

        private int privOfNews;

        public int PrivOfNews
        {
            get { return privOfNews; }
            set { privOfNews = value; }
        }

        private int privOfComment;

        public int PrivOfComment
        {
            get { return privOfComment; }
            set { privOfComment = value; }
        }

        private int privOfMessage;

        public int PrivOfMessage
        {
            get { return privOfMessage; }
            set { privOfMessage = value; }
        }

        private int activation;

        public int Activation
        {
            get { return activation; }
            set { activation = value; }
        }

        private int auditPriv;

        public int AuditPriv
        {
            get { return auditPriv; }
            set { auditPriv = value; }
        }

        private int manageUserPriv;

        public int ManageUserPriv
        {
            get { return manageUserPriv; }
            set { manageUserPriv = value; }
        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="type">用户类型</param>
        /// <param name="id">用户id</param>
        /// <param name="newsNum">新鲜事数量</param>
        /// <param name="commentNum">评论数量</param>
        /// <param name="likeNum">受到顶数量</param>
        /// <param name="dislikeNum">受到踩的数量</param>
        /// <param name="privOfNews">发布新鲜事权限</param>
        /// <param name="privOfComment">发布评论权限</param>
        /// <param name="privOfMessage">私信权限</param>
        /// <param name="auditPriv">管理员的审核权限</param>
        /// <param name="manageUserPriv">管理员的管理用户权限</param>
        public UserMInfo(UserType type, int id = 0, int newsNum = 0,
            int commentNum = 0,int likeNum = 0,int dislikeNum = 0,
            int privOfNews = 0,int privOfComment = 0,int privOfMessage = 0,
            int activation = 0, int auditPriv = -1, int manageUserPriv = -1)
        {
            this.uType = type;
            this.id = id;
            this.newsNum = newsNum;
            this.commentNum = commentNum;
            this.likeNum = likeNum;
            this.dislikeNum = dislikeNum;
            this.privOfComment = privOfComment;
            this.privOfComment = privOfComment;
            this.privOfMessage = privOfMessage;
            this.activation = activation;
            this.auditPriv = auditPriv;
            this.manageUserPriv = manageUserPriv;
        }

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public UserMInfo()
        {
            this.uType = UserType.RegisterUser;
            this.id = -1;
            this.newsNum = 0;
            this.commentNum = 0;
            this.likeNum = 0;
            this.dislikeNum = 0;
            this.privOfComment = 0;
            this.privOfComment = 0;
            this.privOfMessage = 0;
            this.activation = 0;
            this.auditPriv = 0;
            this.manageUserPriv = 0;
        }
    }

    /// <summary>
    /// 用户关系表
    /// </summary>
    public class UserRelation
    {
        private List<int> follow;

        public List<int> Follow
        {
            get { return follow; }
            set { follow = value; }
        }

        private List<int> fans;

        public List<int> Fans
        {
            get { return fans; }
            set { fans = value; }
        }

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public UserRelation()
        {
            follow = new List<int>();
            fans = new List<int>();
        }

        /// <summary>
        /// 带参数构造函数
        /// </summary>
        /// <param name="follow">关注列表</param>
        /// <param name="fans">粉丝列表</param>
        public UserRelation(List<int> follow, List<int> fans)
        {
            this.follow = follow;
            this.fans = fans;
        }

        /// <summary>
        /// 增加关注对象
        /// </summary>
        /// <param name="i">关注ID</param>
        public void AddFollow(int i)
        {
            follow.Add(i);
        }

        /// <summary>
        /// 取消关注对象
        /// </summary>
        /// <param name="i">取消关注对象的ID</param>
        public void RemoveFollow(int i)
        {
            follow.Remove(i);
        }

        /// <summary>
        /// 增加粉丝
        /// </summary>
        /// <param name="i">粉丝ID</param>
        public void AddFans(int i)
        {
            fans.Add(i);
        }

        /// <summary>
        /// 移除粉丝
        /// </summary>
        /// <param name="i">粉丝ID</param>
        public void RemoveFans(int i)
        {
            fans.Remove(i);
        }

        public int GetFollowNum()
        {
            return follow.Count;
        }

        public int GetFansNum()
        {
            return fans.Count;
        }
    }


    /// <summary>
    /// 用户信息，包括了个人信息，管理信息，关系信息
    /// </summary>
    public class UserInfo
    {
        private UserMInfo mInfo;
        
        public UserMInfo MInfo
        {
            get { return mInfo; }
            set { mInfo = value; }
        }

        private UserPInfo pInfo;

        public UserPInfo PInfo
        {
            get { return pInfo; }
            set { pInfo = value; }
        }

        private UserRelation relation;

        public UserRelation Relation
        {
            get { return relation; }
            set { relation = value; }
        }

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public UserInfo()
        {
            mInfo = new UserMInfo();
            pInfo = new UserPInfo();
            relation = new UserRelation();
        }

        /// <summary>
        /// 带参数的构造函数
        /// </summary>
        /// <param name="pInfo">用户个人信息</param>
        /// <param name="mInfo">用户管理信息</param>
        /// <param name="relation">用户关系信息</param>
        public UserInfo(UserPInfo pInfo, UserMInfo mInfo, UserRelation relation)
        {
            this.pInfo = pInfo;
            this.mInfo = mInfo;
            this.relation = relation;
        }
    }

    /// <summary>
    /// 新鲜事状态
    /// </summary>
    public enum NewsStateType
    {
        Auditing = 1,
        Pass = 2,
        Fail = 3,
        NoComment = 4
    }

    /// <summary>
    /// 类别
    /// </summary>
    public enum NewsCategoryType
    {

    }

    public class News
    {
        private int id;

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        private int userBelong;

        public int UserBelong
        {
            get { return userBelong; }
            set { userBelong = value; }
        }

        private int likeNum;

        public int LikeNum
        {
            get { return likeNum; }
            set { likeNum = value; }
        }

        private int dislikeNum;

        public int DislikeNum
        {
            get { return dislikeNum; }
            set { dislikeNum = value; }
        }

        private int commentNum;

        public int CommentNum
        {
            get { return commentNum; }
            set { commentNum = value; }
        }

        private string content;

        public string Content
        {
            get { return content; }
            set { content = value; }
        }

        private string time;

        public string Time
        {
            get { return time; }
            set { time = value; }
        }

        private string tag;

        public string Tag
        {
            get { return tag; }
            set { tag = value; }
        }

        private string title;

        public string Title
        {
            get { return title; }
            set { title = value; }
        }

        private NewsStateType state;

        internal NewsStateType State
        {
            get { return state; }
            set { state = value; }
        }

        private NewsCategoryType category;

        internal NewsCategoryType Category
        {
            get { return category; }
            set { category = value; }
        }

        private String image;

        public String Image
        {
            get { return image; }
            set { image = value; }
        }

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public News()
        {
            id = -1;
            userBelong = -1;
            likeNum = 0 ;
            dislikeNum = 0;
            commentNum = 0;
            image = "";
            content = "";
            time = "";
            tag = "";
            title = "";
            state = NewsStateType.Auditing;
            //category = ;
        }

        /// <summary>
        /// 带参数构造函数
        /// </summary>
        /// <param name="userBelong"></param>
        /// <param name="content"></param>
        /// <param name="title"></param>
        /// <param name="image"></param>
        /// <param name="likeNum"></param>
        /// <param name="dislikeNum"></param>
        /// <param name="commentNum"></param>
        /// <param name="id"></param>
        /// <param name="time"></param>
        /// <param name="tag"></param>
        /// <param name="state"></param>
        public News(int userBelong,
            string content = "",
            string title = "",
            string image = "",
            int likeNum = 0,
            int dislikeNum = 0,
            int  commentNum = 0,
            int id = -1,
            string time = "",
            string tag = "",
            NewsStateType state = NewsStateType.Auditing
            /*NewsCategoryTypecategory = ;*/)
        {
            this.userBelong = userBelong;
            this.content = content;
            this.title = title;
            this.image = image;
            this.likeNum = likeNum;
            this.dislikeNum = dislikeNum;
            this.commentNum = commentNum;
            this.id = id;
            this.time = time;
            this.tag = tag;
            this.state = state;
            this.image = image;

        }
    }

    /// <summary>
    /// 评论
    /// </summary>
    public class Comment
    {
        private int id;

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        private int newsBelong;

        public int NewsBelong
        {
            get { return newsBelong; }
            set { newsBelong = value; }
        }

        private int userBelong;

        public int UserBelong
        {
            get { return userBelong; }
            set { userBelong = value; }
        }

        private int commentBelong;

        public int CommentBelong
        {
            get { return commentBelong; }
            set { commentBelong = value; }
        }

        private string content;

        public string Content
        {
            get { return content; }
            set { content = value; }
        }

        private string time;

        public string Time
        {
            get { return time; }
            set { time = value; }
        }

        private int isRead;
        //isRead = 0:两者都没读；1：新鲜事作者已读评论对象未读；2：新鲜事作者未读评论对象已读；3：两者都读
        public int IsRead
        {
            get { return isRead; }
            set { isRead = value; }
        }

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public Comment()
        {
            id = -1;
            newsBelong = -1;
            userBelong = -1;
            commentBelong = -1;
            content = null;
            time = null;
            isRead = 0;
        }

        /// <summary>
        /// 含参构造函数
        /// </summary>
        public Comment(string content, 
            int newsBelong, 
            int userBelong, 
            int commentBelong = -1, 
            string time = null,
            int isRead = 0,
            int id = -1)
        {
            this.content = content;
            this.newsBelong = newsBelong;
            this.userBelong = userBelong;
            this.commentBelong = commentBelong;
            this.time = time;
            this.id = id;
            this.isRead = isRead;
        }
    }

    /// <summary>
    /// 私信
    /// </summary>
    public class Message
    {
        private int id;

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        private int sendID;

        public int SendID
        {
            get { return sendID; }
            set { sendID = value; }
        }

        private int receiveID;

        public int ReceiveID
        {
            get { return receiveID; }
            set { receiveID = value; }
        }

        private string time;

        public string Time
        {
            get { return time; }
            set { time = value; }
        }

        private string content;

        public string Content
        {
            get { return content; }
            set { content = value; }
        }

        private bool isRead;

        public bool IsRead
        {
            get { return isRead; }
            set { isRead = value; }
        }

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public Message()
        {
            id = -1;
            sendID = -1;
            receiveID = -1;
            time = null;
            content = null;
            isRead = false;
        }

        /// <summary>
        /// 含参构造函数
        /// </summary>
        public Message(string content,
            int sendID,
            int receiveID,
            string time,
            bool isRead = false,
            int id = -1)
        {
            this.id = id;
            this.sendID = sendID;
            this.receiveID = receiveID;
            this.time = time;
            this.content = content;
            this.isRead = isRead;
        }
    }

    /// <summary>
    /// 管理动作
    /// </summary>
    public enum ActionType
    {
        LetPass = 0, 
        LetFail = 1,
        SetPrivilege = 2, 
        Remove = 3,
        Add = 4,
        NoAction = 5
    }

    /// <summary>
    /// 管理动作对象
    /// </summary>
    public enum ObjectType
    {
        ANews = 0, 
        AUser = 1,
        AnAdministrator = 2,
        UserNewsPriv = 3,
        UserCommentPriv = 4, 
        UserMessagePriv = 5,
        AuditingPriv = 6, 
        ManagePriv = 7,
        Nothing = 8
    }

    /// <summary>
    /// 管理记录
    /// </summary>
    public class ManageHistory
    {
        private int id;

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        private int administrator;

        public int Administrator
        {
            get { return administrator; }
            set { administrator = value; }
        }

        private ActionType action;

        internal ActionType Action
        {
            get { return action; }
            set { action = value; }
        }

        private ObjectType manageObject;

        internal ObjectType ManageObject
        {
            get { return manageObject; }
            set { manageObject = value; }
        }

        private int objectUser;

        public int ObjectUser
        {
            get { return objectUser; }
            set { objectUser = value; }
        }

        private string time;

        public string Time
        {
            get { return time; }
            set { time = value; }
        }

        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ManageHistory()
        {
            id = -1;
            administrator = -1;
            action = ActionType.NoAction;
            manageObject = ObjectType.Nothing;
            objectUser = -1;
            time = null;
        }

        /// <summary>
        /// 含参构造函数
        /// </summary>
        /// <param name="administrator">管理者ID（int）</param>
        /// <param name="action">管理行为（ActionType）</param>
        /// <param name="manageObject">管理对象(ObjectType)</param>
        /// <param name="objectUser">管理的用户（int）</param>
        /// <param name="time">时间(stirng)</param>
        /// <param name="id">本记录在数据库中的ID(int)</param>
        public ManageHistory(int administrator,
            ActionType action,
            ObjectType manageObject,
            int objectUser,
            string time,
            int id = -1)
        {
            this.administrator = administrator;
            this.action = action;
            this.manageObject = manageObject;
            this.objectUser = objectUser;
            this.id = id;
            this.time = time;
        }

    }
}